package demo.practice.tree.depth;

import demo.practice.TreeNode;

public class P111 {


//    public int minDepth(TreeNode root) {
//
//    }

    //     1
    //  2,  3
    //2,5

    public static void main(String[] args) {
        P111 p111= new P111();
        TreeNode root= new TreeNode(1);
        root.right= new TreeNode(3);
        root.left= new TreeNode(2);
        root.left.right= new TreeNode(5);
        root.left.left= new TreeNode(2);
        p111.minDepth(root);
    }

    public int minDepth(TreeNode root) {

        if(root==null)
            return 0;

        if(root.left==null&&root.right==null)
            return 1;

        if(root.left == null)
            return minDepth(root.right)+1;

        if(root.right==null)
            return minDepth(root.left)+1;

        return Math.min(minDepth(root.left)+1,minDepth(root.right)+1);
    }

}
